<template>
    <div>
        <!-- 一，面包屑导航区域 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>

        <!-- 二，卡片视图区域 -->
        <el-card>
            <!-- 1，搜索和添加区域，layout布局，行  -->
            <el-row>
                <el-col :span="6">
                    <el-input placeholder="请输入内容">
                        <el-button slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <!-- 2，订单列表区域，table -->
            <el-table :data="orderlist" stripe border>
                <el-table-column label="#" type="index" width="50"></el-table-column>
                <el-table-column label="订单编号" property="order_number" width="180">
                </el-table-column>
                <el-table-column label="订单价格" property="order_price" width="100">
                </el-table-column>
                <el-table-column label="是否付款" property="order_pay" width="100">
                    <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.order_pay === '1'">已付款</el-tag>
                        <el-tag type="warning" v-else>未付款</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="是否发货" property="is_send" width="100">
                </el-table-column>
                <el-table-column label="下单时间" property="create_time" width="150">
                    <template slot-scope="scope">
                        {{ scope.row.create_time | dataFormat }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="150">
                    <template>
                        <el-button type="primary" icon="el-icon-edit" size="mini" @click="showBox()"></el-button>
                        <el-button type="success" icon="el-icon-location" size="mini" @click="showProgressBox()">
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 3，分页区域 -->
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum" :page-sizes="[1, 3, 5, 10]" :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </el-card>
        <!-- 三，修改地址对话框 -->
        <el-dialog title="修改地址" :visible.sync="addressDialogVisible" width="50%" @close="addressDialogClosed()">
            <el-form :model="addressForm" :rules="addressFormRules" ref="addressFormRef" label-width="100px">
                <el-form-item label="省市区/县" prop="address1">
                    <!-- <el-input v-model="addressForm.address1"></el-input> -->
                    <!-- 级联选择器， -->
                    <el-cascader v-model="addressForm.address1" :options="cityData" :props="{ expandTrigger: 'hover' }">
                    </el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="addressForm.address2"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="addressDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="addressDialogVisible = false">确 定</el-button>
            </div>
        </el-dialog>
        <!-- 四，查询物流对话框 -->
        <el-dialog title="物流信息" :visible.sync="progressDialogVisible" width="50%">
            <!-- 时间线 -->
            <el-timeline >
                <el-timeline-item v-for="(activity, index) in progressInfo" :key="index" :timestamp="activity.time">
                    {{ activity.context }}
                </el-timeline-item>
            </el-timeline>
            <span slot="footer" class="dialog-footer">
                <el-button @click="progressDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="progressDialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<!-- 
    订单列表组件order.vue
    1，建好骨架，路由配置。
    2，骨架完善。面包屑，卡片区域，数据列表发送请求,data定义好queryInfo,orderlist，接着数据渲染。table,时间用过滤器，操作加按钮，是否付款加tag判断，
    3，分页，监听变化，重新渲染列表。
    4，修改地址对话框，显示隐藏showBox，data定义addressDialogVisible,addressForm，校验addressFormRules。平级放入省市数据文件cityData.JS,导入，在data中引用，级联选择器。关闭清空。
    5,查询物流对话框.显示隐藏showProgressBox,发送请求。progressInfo,这里由于要使用的时间线timeline是要2.6以上UI版本，但安装的是低版本，所以要额外引入时间线import。导入插件，引入，注册。style处也导入对应样式。
    6,提交代码。

 -->
<script>
import cityData from './citydata.js';

export default {

    data() {
        return {
            // 订单列表请求参数
            queryInfo: {
                query: '',
                pagenum: 1,
                pagesize: 3,
            },
            // 订单列表请求数据列表
            orderlist: [],
            total: 0,
            // 修改地址对话框，显示隐藏
            addressDialogVisible: false,
            // 修改地址对话框，表单数据
            addressForm: {
                address1: [], //级联选择器，数组
                address2: '',
            },
            addressFormRules: {
                address1: [{ required: true, message: '请输入省市区/县', trigger: 'blur' },],
                address2: [{ required: true, message: '请输入详细地址', trigger: 'blur' },]
            },
            // 省市数据
            cityData: cityData,
            // 查询物流对话框，显示隐藏
            progressDialogVisible: false,
            // 查询物流对话框，请求数据列表
            progressInfo: [],
        };
    },

    created() {
        this.getOrderList()
    },

    methods: {
        // 订单列表请求 
        async getOrderList() {
            const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
            console.log(res)
            if (res.meta.status !== 200) {
                return this.$message.error(res.meta.msg)
            }
            this.orderlist = res.data.goods
            this.total = res.data.total
            console.log(this.orderlist)
            this.$message.success(res.meta.msg)
        },
        // 分页,监听条数变化
        handleSizeChange(newSize) {
            console.log(newSize)
            this.queryInfo.pagesize = newSize
            this.getOrderList()
        },
        // 分页,监听哪一页变化
        handleCurrentChange(newPage) {
            this.queryInfo.pagenum = newPage
            this.getOrderList()
        },
        // 修改地址对话框，显示隐藏
        showBox() {
            this.addressDialogVisible = true
        },
        // 修改地址对话框，关闭，清空
        addressDialogClosed() {
            this.$refs.addressFormRef.resetFields()
        },
        // 查询物流对话框，显示隐藏,发送请求
        async showProgressBox() {
            // const { data: res } = await this.$http.get('/kuaidi/1106975712662')
            const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
            console.log(res)
            if (res.meta.status !== 200) {
                return this.$message.error(res.meta.msg)
            }
            this.$message.success(res.meta.msg)
            this.progressInfo = res.data
            this.progressDialogVisible = true
        },
    },
};
</script>

<style lang="less" scoped>

@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item\(1\).css';

.el-cascader {
    width: 100%
}
</style>